<template>
	<div class="login">
		<div class="name-box">
			<text class="name"> 手机号 : </text>
			<input type="text" placeholder="请输入手机号" v-model="phone">
		</div>

		<div class="password-box">
			<text class="password"> 密码 : </text>
			<input type="password" placeholder="请输入密码" v-model="psw">
		</div>
		<button @click="login"> 登录 </button>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				psw: '',
			}
		},
		methods: {

			// 登录

			login() {
				uni.request({
					url: 'http://192.168.36.46:3000/patient/find/registerTel?phone=' + this.phone
				}).then(res => {
					console.log("登陆=>", res.data.data[0])
					 window.localStorage.setItem("patientName", res.data.data[0].patientName);
					  window.localStorage.setItem("age", res.data.data[0].age);
					    window.localStorage.setItem("sex", res.data.data[0].sex);
						   window.localStorage.setItem("phone", res.data.data[0].phone);
					if (res.data.code == 200) {
						if (res.data.data[0].password == this.psw) {
							uni.showToast({
								icon: 'success',
								title: '登录成功',
								duration: 2000
							})
							uni.navigateTo({
								url: '/pages/Visits/Visits?name='+ res.data.data[0].patientName
							})
						} else {
							uni.showToast({
								icon: 'error',
								title: '手机或密码不正确',
								duration: 1000
							})
						}
					} else if (res.data.code == 500) {
						uni.showToast({
							icon: 'error',
							title: res.data.msg,
							duration: 2000
						})
					}

				})
			},

		}
	}
</script>

<style lang="scss">
	* {
		padding: 0px;
		margin: 0px;
	}

	.login {
		margin-top: 100px;

		.name-box,
		.password-box {
			display: flex;
			justify-content: center;
			margin: 20px 0px;

			input {
				text-indent: 20px;
			}
		}

		button {
			width: 300px;
			height: 50px;
			color: #fff;
			margin: 30px auto;
			outline: none;
			border: none;
			background-color: #6cc9b6;

		}

	}
</style>